<?php

namespace app\api\model;

use app\exceptions\ApiException;
use think\Model;

/**
 * Banner
 */
class VipUpgrade extends Model
{
    // 表名
    protected $name = 'vip_upgrade';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;


    public function getVipUpgradeRecord($prams){
        $member_id = $prams['member_id'] ?? 0;
        $vip_card = (new VipCard())->column('name','id',);
        $list = self::alias('vo')
            ->where(['member_id' => $member_id,'status' => 1])
            ->paginate(10)->toArray();

        if(!$list) return api_message();
        foreach($list['data'] as & $v){
            $v['create_time'] = date("Y-m-d H:i:s",$v['create_time']);
            $v['old_vip_name'] = $vip_card[$v['old_vip_card_id']] ?? '';
            $v['new_vip_name'] = $vip_card[$v['new_vip_card_id']] ?? '';
            $v['pay_time'] =date("Y-m-d H:i:s",$v['pay_time']);
        }
        return api_message($list);
    }

}
